/* BeerScreen, Copyright (C) 2010 Gabriel Tremblay <initnull@gmail.com>
 * http://www.etrange.ca/beerscreen
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ca.etrange.beerscreen.view;

import java.awt.Component;

import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

public class TransparentJTable extends JTable {
	private static final long serialVersionUID = 5273051559736999196L;

	public TransparentJTable(){
		this.setOpaque(false);
		this.setShowGrid(false);
	}
	
	/**
	 * This method set each cell to transparent.
	 * Found this bit of code on codeguru forums.
	 */
	@Override
	public Component prepareRenderer(TableCellRenderer renderer,
			int row, int column) {
		Component component = super.prepareRenderer(renderer, row, column);
		// We want renderer component to be
		// transparent so background image is visible
		if (component instanceof JComponent) {
			((JComponent) component).setOpaque(false);
		}
		return component;
	}
	
	/**
	 * Table is unselectable
	 */
	@Override
	public void changeSelection(int rowIndex, int columnIndex,
			boolean toggle, boolean extend) {
		return; // questionable
	}
	
	/**
	 * Table is uneditable
	 */
	@Override
	public boolean isCellEditable(int row, int column) {
		return false;
	}
}
